CHANGELOG
Jan 26, 2023
div::cop
with Reflection and strict modesDec 24, 2023
Feb 11, 2020
minor fix
: Array and string offset access syntax with curly braces is deprecatedrelease
version 5.1.6Sep 21, 2019
release
version 5.1.5fix
div::varExists() methodAgo 23, 2019
release
version 5.1.4Ago 22, 2019
release
version 5.1.3fix
resolution of templates path for win and *nix OSfix
the relative path of included templates inside loopAgo 21, 2019
release
version 5.1.2fix
orphan conditional partsfix
standalone preprocessed templatescmp.tpl
This is a generic template for create visual components. Each component have a face or content, and more child components. Each child can located in the face of their parent. The template self call recursively.
{strip}
?$location {{{$location} $location?
?$face {$face} $face?
?$components
[$components] component =>
{= component.div.standalone: true =}
{%% cmp: component %%}
[/$components]
$components?
?$location {$location}}} $location?
{/strip}
Button.tpl
<button>{$icon}{$caption}</button>
Page.tpl
<h1>Buttons</h1>
(( top ))
<p>Click on the buttons: <p/>
(( bottom ))
<h1>Fruits</h1>
(( fruits ))
index.php
<?php
use divengine\div;
echo new div("cmp", [
"id" => "welcomePage",
"face" => "{% Page2 %}",
"components" => [
[
"face" => "{% Button %}",
"location" => "top",
"caption" => "Click me",
"icon" => '*'
],
[
"face" => "{% Button %}",
"location" => "bottom",
"caption" => "Click me again",
"icon" => '#'
],
[
"face" => "<ul>(( items ))</ul>",
"location" => "fruits",
"components" => array_map(function ($caption) {
return [
"face" => "<li>{$caption}</li>", // or "<li>{\$caption}</li>" :D
"location" => "items"
];
}, ["Banana", "Apple", "Orange"])
]
]
]
);
Jul 22, 2019
release
version 5.1.1improvement
support namespaces of div's childrelease
version 5.1.0 improvement
: Better resolution of default template for child classes of div, using Reflection!/some/folder/in/the/end/of/the/world/Page.tpl
Hello people
/some/folder/in/the/end/of/the/world/Page.php
<?php4
use divengine\div;
class Page extends div {
}
/index.php
<?php
include '/some/folder/in/the/end/of/the/world/Page.php';
echo new Page();
Output
Hello people
Jul 6, 2019
bugfix
in div::scanMatchJul 3, 2019
bugfix
: Fix scope of standalone pre-precessed templates. This fix prevent infinite loops and is util for recursive pre-process in a component based design.index.tpl
{= foo: "bar" =}
{%% component: {
div: {standalone: true}, // ignore parent scope
zoo: "monkey"
} %%}
component.tpl
{$zoo}
{$foo} <!--{ not exists in this scope }-->
Jul 2, 2019
MyComponent.php
MyComponent extends div {
....
}
index.tpl:
{%% component: {
div: {
engine: "MyComponent"
},
someProperty: "bla"
} %%}
Jun 27, 2019
PHP
echo new div('Var is: {$var}', ['var' => null]);
OUTPUT before this change:
Var is: {$var}
OUTPUT after this change:
Var is:
important change!
: Fix scope of pre-processed templates inside loopsDo not pre-process anything within the loops blocks if the loops have not been resolved
The following code did not work as expected, because the pre-process was executed before doing the loop. So the $col
variable did not exist and logic of the template will be broken.
[$cols] col =>
{%% element: {
tag: "td",
attrs: $col.attrs,
inner: $col.content
} %%}
[/$cols]
Jun 14, 2019
bugfix
: better resolution of tags with empty suffix. In this example "list.filter" is a substring of "list.filter.category", and then exists resulting unexpected code if $list.filter is falseTPL
?$list.filter
AAA
?$list.filter.category
BBB
$list.filter.category?
CCC
$list.filter?
OUTPUT
?$list.filter
AAA
The fix was for other similar situations in div::getBlockRanges().
The stop chars are the same in favor of text plain and XML family:
$stop_chars = ["<", ">", ' ', "\n", "\r", "\t"];
Sep 20, 2018
In PHP 7 (phpng), is_null is actually marginally faster than ===
, although the performance difference between the two is far smaller.
PHP 5.5.9
is_null - float(2.2381200790405)
=== - float(1.0024659633636)
=== faster by ~100ns per call
PHP 7.0.0-dev (built: May 19 2015 10:16:06)
is_null - float(1.4121870994568)
=== - float(1.4577329158783)
is_null faster by ~5ns per call
Aug 19, 2018
bugfix
on constructor, when div var is an object and not an arrayOct 8, 2017
{= i18n: i18n/{$lang}.json =}
"i18n/{$lang}.json"
without quotes is invalid JSON
Then, don't use quotes:
{= i18n: "i18n/{$lang}.json" =}
relative -->
|
v
/app/site/view/i18n/en/messages.json
^
|
replacement result
/app/site/view/page.tpl
{= lang: "en" =}
{= i18n: i18n/{$lang}/messages.json =}
{$i18n.message1}
/app/site/view/i18n/en/messages.json
{
message1: "Hello"
}
Output:
Hello
Oct 7, 2017
->loadTemplateProperties()
to publicprepareDialect()
...->prepareDialect()
for disable automatic updateSep 30, 2017 [my birthday :)]
getAuxiliaryEngine
(clone vs assignment)div.class_name
: the name of current invoked class ('div' or child of 'div')div.super_class_name
: the name of super parent of current invoked class name (normally is 'div')Sep 25, 2017
Sep 9, 2017
[$blocks]
{% blocks/block-{$id}.tpl %}
[/$blocks]
Jun 2, 2017
$tpl = new div("index.tpl", []);
Translate from other dialect to current dialect:
$tpl->translateFrom($dialectFrom);
Translate from current dialect to other dialect:
$tpl->translateTo($dialectFrom);
Translate from any dialect to any dialect:
$tpl->translate($dialectFrom, $dialectTo, $src, $items);
Maybe you need prepare the current dialect first:
prop = $tpl->getTemplateProperties();
$tpl->__src = $tpl->prepareDialect(null, $prop);
May 29, 2017
div.standalone
, by default is FALSE.{= foo: value =}
{%% block.tpl: {
div: {
standalone: true
}
} %%}
This better facilitates the recursive inclusion of templates, useful in generation of source code and other hierarchies like XML, HTML, JSON, etc.
?$block
{%% block: {...} %%} <-- wait for block question results
$block?
{= block: {
var1: "value1"
var2: "value2"
} =}
Take the block value
{%% tpl: block %%}
Take json from external file
{%% tpl: block.json %%}
December 22, 2016
November 16, 2016
[$parentloop] parent =>
[$childloop] child =>
Parent key: {$parent._key}
Child key: {$_key} or {$child._key}
[/$childloop]
[/$parentloop]
November 14, 2016
Syntax:
{join} varname | delimiter {/join}
index.tpl
{= tags: ['a','b', 'c'] =}
{join} tags |, {/join}
{join} tags |,{/join}
{join} tags {/join}
Output:
a, b, c
a,b,c
abc
October 10, 2016
January 12, 2016
December 24, 2015
div::translateFrom
December 23, 2015
by default you use:
{$person.name}
but now you can do...
index.php
<?php
define('DIV_TAG_VAR_MEMBER_DELIMITER','->');
include "div.php";
echo new div("index.tpl", array(
'person' => array(
'name' => 'Peter',
'child' => array(
'name' => 'eli'
)
)
));
index.tpl
{$person->child->name}
{$person->name}
TODO: improve dialect creator tool
TODO: check dialect translator method div::translateFrom()
December 19, 2015
December 12, 2015
gracix
and Takefumi Ota
Example:
index.php
<?php
class Person {
...
public function getFullName(){
return $this->first_name.' '.$this->last_name;
}
...
}
echo new div('index.tpl', array("person" => new Person(...)));
index.tpl
{= fullname: ->person.getFullName() =}`
The full name is {$fullname}
December 11, 2015
December 1, 2014
November 24, 2014
div::isValidPHPCode()
October 7, 2014
__temp['vars']
var in parseMacros();
because because get_defined_vars
return also vars
div::cop();
October 6, 2014
div.clear_locations
(= true by default). This means that the locations will be clear or not at the end (parse_level = 0). Then, the component are more flexible with pre-processed templates: comp.tpl
(( before )) <input type="{$type}" name="{$name}"> (( after ))
index.tpl
{%% comp: {
type: "text",
name: "first_name",
div: {
clear_locations: false
}
} %%}
<!--{ If div.clear_locations is true (by default), the next code don't work }-->
{{before <label>First Name</label> before}}
{{after <input type="submit"> after}}
September 26, 2014
parseData()
vs parseMatch()
logical orderSeptember 23, 2014
parsePreprocessed()
when $pdata is nullSeptember 21, 2014
index.tpl
{% subtpl: {
from: "<!--{ begin }-->",
to: "<!--{ end }-->",
offset: 2,
limit: 1
} %}
subtpl.tpl
Any text...
<!--{ begin }-->Some text 1<!--{ end }-->
Any text...
<!--{ begin }-->Some text 2<!--{ end }-->
Any text
September 20, 2014
array_keys
get_object_vars
is_object
div::div():
index.php
<?php
echo div::div('index.tpl', array("item1" => "value1"));
<? break; ?>
Output
Fatal error: Cannot break/continue 1 level in div.php: eval()'d code on line 1
September 17, 2014
September 16, 2014
{= somearray[]: "new item" =}
New feature for preprocessed templates: specific data
Syntax:
{}
data is: json, name of var or filename with json
Example:
Now is more simple for build the components:
{%% form: {
action: "login.php",
method: "post.php",
fields: [
{
type: "text",
name: "user",
label: "User"
},{
type: "password",
name: "pass",
label: "Password"
}
],
submit: {
value: "login",
name: "btnLogin"
}
} %%}
{= content: ->getPage(file_put_contents('some.txt','some text')) =}
Example:
{= div.literals: ["text1", "text2"] =}
{$text1}
{$text2}
{$text3}
echo new div('index.tpl', array(
'text1' => '{/ignore}[:1,5:] {$value} [/]{ignore}', // I am being about deceiving the security
'text2' => '[:1,100;] text to repeat [/]',
'text3' => '[:1,3;] some [/]'
));
[:1,5;] {$value} [/]
[:1,100;] text to repeat [/]
some some some
An important bug was fixed: the memory in the loops:
In div 4.4 dont't work:
Integration with Google Chrome/Console and Mozilla Firefox/Firebug plugins.
Now the engine's messages will be appear in this browsers's features.
Improvement of detection of infinite loops in recursive replacements:
{= bar: {
{= e: 'bar'} =}
{$bar}
FATAL ERROR WAS DETECTED AN INFINITE LOOP IN RECURSIVE REPLACEMENT OF $foo.
Improvement of parser and bugs fixes: if foo not existed, widget waits forever.
Now the next example works:
{= widget: 45 =}
{?( "{$foo}" == "a" )?}
{= bar: 5 =}
{/?}
{$widget}
45
Solved!
Improvement of relative include/preprocessed templates.
Now the next example works:
{% folder/tpl1 %}
{% folder2/tpl2 %}
{% tpl3 %}
Hello
Hello
Improvement of template's variables assignment.
Now the next example works:
{= position: "absolute" =}
{?( "{$position}" == "absolute" )?}
{= absolute: true =}
@else@
{= absolute: false =}
{/?}
?$absolute YES $absolute?
YES
Improvement of the variables's scope:
Now the next example works:
{= foo: true =}
{= bar: [1,2,3] =}
?$foo
YES
$foo?
[$bar]
{= foo: (# {
YES
@else@
NO
{$foo}
YES
NO
YES
YES
true
Improvement of the parser of template's vars:
If the value is not valid JSON, it will be considered as
a template and will be parsed before decoding.
See the next sequence:
See the difference:
Improvement of the parser of template's variables. Was improved
the detection of assignment of variables in any part of the
JSONs values. For example:
{= cities: ["New York", "Tokyo"] =}
{= combobox: {
id: "cboCities",
options: $cities
} =}
{$combobox.options.0}
New York
Improvement of the parser of ignored parts
Improvement of the parser of includes
New feature: template's documentation. Now in the comments you can
document the template. The documentation's parts have @ as prefix. For example:
<!--{
@icon [[]]
@type Div PHP Template Engine Component
@name Simple Combobox
@autor Rafael Rodriguez Ramirez <[email protected], [email protected]>
@version 1.0
@update 1/06/2013
@website http://divengine.com
@property optional <string> id
@property optional <string> class
@property optional <string> name
@property optional <string> label
@property optional <number> default
@property required <array> options
@example
[[_
{= class: "combo" =}
{= id: "cboCities" =}
{= name: "cboCities" =}
{= options: ["New York", "Tokyo", "Havana"] =}
{= default: 1 =}
{= label: "Cities" =}
{% components/div-cmp-simple-combobox %}
_]]
}-->
To obtain the documentation data:
$data = div::getDocs();
To obtain a readable documentation:
echo div::getDocsReadable(/* optional template */);
Fix the algorithm of getRanges().
Fix the parser of macros.
Added a new sub-parser's event: afterReplace.
Improvement of the algorithm of getRanges() to make all the possible one. Now
Div continues searching ranges after unclosed tags.
- For next template:
index.tpl
----------
{/
{/div.now/}
- In previous versions (1.0 - 4.1):
Output:
----------
{/
{/div.now/}
- From Div 4.2:
Output:
----------
{/
2013-05-31
Fixed some bugs in locations and conditional parts.
Created a translator of dialects. Now div have 2 new public methods:
$tpl = new div('templateWithDialectX.tpl', $data);
$dialectY = 'json code'; // or associative array
// Return the translated template
// Translate and change the original template
New feature: template properties. Now you can specify some properties
in the template's code, for example, the dialect of the current template:
Example:
index.tpl
------------------------------
@_DIALECT = smarty.dialect
{* this is a comment *}
Name: {$name}
{literal}
{$name}
{/literal}
{% other %}
other.tpl
------------------------------
@_DIALECT = twig.dialect
{{ foo.bar }}
smarty.dialect
------------------------------
{
'DIV_TAG_IGNORE_BEGIN': '{literal}',
'DIV_TAG_IGNORE_END': '{/literal}',
'DIV_TAG_COMMENT_BEGIN': '{*',
'DIV_TAG_COMMENT_END': '*}'
}
twig.dialect
-------------------------------
{
'DIV_TAG_REPLACEMENT_SUFFIX': ' }}',
'DIV_TAG_MODIFIER_SIMPLE': '{ '
}
index.php
-------------------------------
<?php
include "div.php";
echo new div("index.tpl", array(
'name' => 'Peter',
'foo' => array(
'bar' => 45
)
));
Output
-------------------------------
Name: Peter
{$name}
45
New feature: predefined subparsers. Div provide pre-defined sub-parsers, for example,
{parse}...{/parse}. This example of sub-parser make a pre-proccess of enclosed code.
This means that a new instance of div will be created, similar to the loops
and the capsules. Other predefined subparsers will be developed in future releases.
New feature: sub-parser's events. Now in the templates's code you can specify when
a sub-parser will be executed: beforeParse, afterInclude or afterParse. Example:
index.tpl
---------------------------
{= name: "Peter" =}
{= products: [
{
name: "banana",
price: 40
},
{
name: "potato",
price: 25
}
] =}
[$products]
{parse:beforeParse}
Name: {
{% other %}
[/$products]
other.tpl
{parse:beforeParse}
Other name: {$name}
{/parse:beforeParse}
Output
--------------------------------------
Name: Peter
Product name: banana
Other name: banana
Name: Peter
Product name: potato
Other name: potato
Enable custom dialect for developers!
A dialect is defined by the group of constant whose name
begins with DIV_TAG. This dialect is subject to some simple
rules that Div forces to complete for preveer inconsistencies and
infinite loops.
New static method isValidCurrentDialect, for detect error in the
definition of current dialect, based on this rule:
The interpretation of date format was improved.
If you need type the char ":" in the format, and this
char is the separator between var and format, then type
a backslash before ":", like as this:
{/2012-01-01 00:30:00 : Y-m-d h:i:s/}
In the example the value is "2012-01-01 00:30:00 " and
the format is "Y-m-d h:i:s".
The interpretation of aggregate functions was improved.
The next example work now:
{= products: [
{name: "Banana", price: 10},
{name: "Potato", price: 20}
] =}
{$products.0.price}
{#products.0.price:2#}
{$sum:products-price}
{#sum:products-price:2,#}
{%sum:products-price}
10
10.00
30
30,00
2
Performance: work remembered! Now the engine can remember some
actions from previous work and increase their speed.
New feature: the macros.
A macro is a restricted PHP code inside the templates to facilitate the complex processing
with the advantages of this language. The security is guaranteed. See the next silly example:
{$title}
Hello world
HELLO WORLD
New feature: the custom sub-parsers
A sub-parser is a parser implmemented by the programmer. For example:
The template variables's manipulation was improved:
Example:
{= product: {
name: "banana"
price: 20
} =}
Name: {^product.name}
Price: ${#product.price:2.#}
{= product.price: (# {$product.price} * 2 #) =}
Double price: ${#product.price:2.#}
[[product
Current price: {$price}
product]]
Output:
Name: banana
Price: $20.00
Double price: $40.00
Current price: 40
New static methods are added:
div::issetVar(
The method setItem and getItem was improved with detection of complex variable's names:
The order respect of template variables's manipulation was improved:
{= a: 5 =}
{$a}
{= a: (# {$a} + 1 #) =}
{$a}
{= a: (# {$a} + 1 #) =}
{$a}
5
6
7
bugfix of template variables when it use object's methods
Now you can call a object's method with some ways:
Similar to PHP:
{= result: ->method(param1, param2, param3) =}
One parameter as JSON data:
{= result: ->method({param1: value1, param2: value2});
bugfix of loops, prevent a recursion with var '_item' as object inside the same object:
Product Object
(
[price] => 0
[quantity] => 0
[_item] => Product Object
RECURSION
)
The scalar values as a complex values! What?
Yes! Now all the scalar values can be used as strings. Then, the strings can be
used like complex values, that is to say, as group of characters. For example:
{= name: "Peter" =}
{$name.0}
{$name.1}
{= x: 537 =}
{$x.0}
{$x.1}
[$name]{
[$x] {
Output:
P
e
5
3
P e t e r
5 3 7 = 105
Version 3.7 was released with a serious error that was corrected in the 3.8
Release the 3.8 version
Improved the interpretation of third parameter of the constructor
as a string with the variables's names.
echo new div('index.tpl', array('name' => 'Peter', 'age' => 25, 'sex' => 'M'), 'name,age');
Release the 3.7 version
Improvement of the speed.
Improvement of the options arround the __toString method of objects in 3 scopes. See the example below.
The old policy:
"if an object has implemented the method __toString then be treated as a string"
It was changed for:
"if an object has implemented the method __toString, you can work with the object as a character string"
Example:
index.php
index.tpl
------------
{$product}
Output for index.tpl
Banana ($10)
index1.tpl
{$value}
is similar to
{$_to_string}
index2.tpl
[[product
{$value}
is similar to
{$_to_string}
product]]
index3.tpl
[$products]
{$value}
is similar to
{
Same output for index1, index2 and index3
Banana ($10)
is similar to
Banana ($10)
From version 3.6 Div maintains a policy regarding the use of objects: if an
object has implemented the method __ toString then be treated as a character string.
We are working to improve the policy and avoid unhappy.
index.php
<?php
include "div.php";
class Product{
public function __construct($name, $price){
$this->name = $name;
$this->price = $price;
}
public function __toString(){
return $this->name.' ($'.$this->price.')';
}
}
echo new div('index.tpl', array("products" => array(new Product('Banana', 10))));
?>
index.tpl
[$products]
{$value}
[/$products]
Output
Banana ($10)
We are working to improve the policy and avoid unhappy.
Some functions of PHP are enabled in formulas and conditions.
Added a new system var named: $div.ascii. This var contain the all chars of ASCII table.
{$div.ascii.64}
is similar to
(# chr(64) #)
but the replacement is faster than calculation
@
is similar to
@
but the replacement is faster than calculation
Added a new feature for programmers: the method changeTemplate()
"Hello world")); echo $tpl; // $tpl->show(); $tpl->changeTemplate('index2.tpl'); echo $tpl; // $tpl->show(); ?>Improvement of the show() method with a new parameter: specific template
title = "Hello world"; $tpl->show('template.tpl'); ?>Added new variable's modifiers:
{&&var} - rawurlencode
{'var} - escape unescaped single quotes
{js:var} - escape quotes and backslashes, newlines, etc.
{$var:[string format]} - format the value with sprintf PHP function
Added new feature for programmers: custom variable's modifier
For add a new custom variable's modifier you need call the method:
div::addCustomModifier($prefix, $function)
The parameter $function can be the name of function or the name of static method of a class, for example
div::addCustomModifier('upper', 'MyModifiers::upper');
index.php
'http://localhost')); ?>{upi:url}
http%3A//localhost
Added new feature for programmers: the hooks!. The hooks are:
beforeBuild, afterBuild, beforeParse, afterParse
Example:
index.php
class HomePage extends div{
public function beforeBuild(){
$this->__src = "index";
$this->setItem(array(
"title" => "Hello World"
));
}
}
echo new HomePage();
index.tpl
Improvement of the setItem method
Improved the access to object's public methods
Release the 3.6 version
Improved the feature "template vars". Now you can execute the "methods of information".
Example:
somedata is: {$somedata}
{= names: ->getNames() =}
The names are: [$names] {
somedata is: 100
The names are: Jones Pete Mark
New feature: locations!
Now you can define a diferent locations in your template
and put in this locations any content.
(( top ))
(( any )) Some content here (( any ))
(( bottom ))
{{top
This is the top of the page
top}}
{{bottom
This is the bottom of the page
bottom}}
{{any
any}}
This is the top of the page
Some content here
This is the bottom of the page
Improvement of the conditional parts: the first and last blank space are removed.
?$what Hello $what?
Hello
?$what Hello $what?
Hello
New feature: @empty@ tag for list's blocks
[$users]
{
Add new feature: Multiple variable's modifiers
{$varname|modifier1|modifier2|modifier3|...|}
{= word: "ABCDEFG" =}
{
{$word|0,3||^|}
{$word|0,3|_|^|~2|}
ABC
abc
Abc
Ab
Fix a bug with {ignore} functionality
Add new vars for the iterations: $_previous and $_next.
{= list: [10,5,7,12,8,8,10,10] =}
[$list]
{= _previous: 0 =}
{= _next: infinite =}
{
0..1..2
1..2..3
2..3..4
3..4..5
4..5..6
5..6..7
6..7..8
7..8..9
8..9..10
9..10..infinite
Algorithm improved: 95% more faster.
Release the 3.2 version
Detection of recursive inclusion as an error. For example:
<!- This include will not take effect -->
{% index %}
Fix important issue for matchs. Now work the follow example:
{= list: [
{
name: "Banana",
price: 20,
shipments: [
{
date: "2012-05-09",
packages: [
[20, 30, 40]
]
}
]
},
{
name: "Potato",
price: 40
}
] =}
{
{
{
{$list.0.shipments.0.adresses.0.0}
Improvements to the template's vars. Now you can do this:
{$body}
{= content: article =}
Header
{$content}
Footer
Delete the DIV_CLASS_NAME constant: now is more simple to change the name of
div class. Simply change the name of div class, no more!
Fix problem of template vars's scope. The inheritance mechanism is more simple now:
{= block1:
...some code here...
=}
{$block1}
{= *block1:
...some another code here...
=}
{% parent %}
The algorithm of text summary was improved.
New feature: IDE's friendly marks
Example:
<p>Name: {$name}</p>
<p>Price: {$price}</p>
<!--| {?( {$price} > 10 )?} |-->
Expensive product
<!--| {/?} |-->
Is similar to:
[$products]
<p>Name: {$name}</p>
<p>Price: {$price}</p>
{?( {$price} > 10 )?}
Expensive product
{/?}
[/$products]
Fixed bugs:
Example:
"some")); // var2 is missing index.tpl ---------- {?( "{$var1}" == "some" && "{$var2}" == "another" )?) Part 1 @else@ Part 2 {/?} Output: ---------- Part 2 - If you don't define a variable, the formula will be ignored: Example: 2)); // var2 is missing index.tpl ---------- (# {$var1} + {$var2} #) Output: ---------- (# 2 + {$var2} #)Fixed bugs
Add new feature for json encode.
Example:
array(1,2,3,4,5))); {json:variable} Outoput: [1,2,3,4,5]Added new features for replacements: multiple replacements
{= replac: [
['search this string', 'replace with this string', false], <!--{ str_replace }->
['search regular expresion','replace with this string or expresion', true]
] =]
{:replac}
... some code here ....
{:/replac}
{= php-code: [
['echo ', 'echo '],
['/'(^'*)'/i', ''$1'',true]
] =}
{:php-code}
{:/php-code}
Fixed bugs
Add new features for performance: enable and disable system var
div::enableSystemVar("div.session");
div::disableSystemVar("div.server");
...
Fixed bugs
Added new funcionality for log: Save the steps of the parser into log file
// Save the steps of the parser into log file
div::logOn("mylogfile.log");
...
Release the 2.5 version
Fixed bugs
Added new functionality: html to text
{txt} ... some html code here .. {/txt}
{txt} width => ... some html code here {/txt}
The width integer parameter, wrap the text with this width.
Fixed bugs
Added new functionality: text wrap
If you needed the wrap of a text with a specific width, you can do this:
{$body:/200}
If you use the br modifier, the text wrap take effect on the web:
{br:body:/200}
Release the 2.4 version
Added new functionality: show the teaser of a text. Similar to get a substring of text:
{$mytext:100}
If you add the symbol ~, you can retrieve the teaser of $mytext:
{$mytext:~100}
NEW: Allow to asign a program var to a template var. For example:
{= another: $some =}
{$another}
5
Also you can asign to the specific property of template var:
{= someobj: {
property: "$some"
} =}
{$someobj.property}
Release the 2.3 version
NEW: Allowed functions. Now the programmer can enable functions
of or written in PHP so that the designer can use them in the templates.
(# sum(2,3) #)
NEW: Add new item to list or set a property of object:
... some more code here ...
{= list: [1,2,3] =}
{= customer: {
name: "Peter",
phone: "222-444555"
} =}
... some more code here ...
{= list[]: 4 =}
{= customer[address]: #221 street 45 =}
... some more code here ...
{$list.4}
{$customer.address}
New functionality: assign to design vars the result of method! If the programmer
implemented a class that inherits of div, then the designer can use the methods of this
class.
Syntax for template:
{= variable: ->methodName(params as JSON) =}
For example:
{= sum: ->getSum(x: 20, y: 30) =}
{$sum}
{= lts: ->getLetters() =}
[$lts] {
50 A B C
Now the definition of data in templates is similar to set a global var in the programmer side
and you can re-refine this data every time in the template and now the sequence of the operations
is not ignored. The variables have arrived!
For example:
{= products: [
{price: 10, qty: 5},
{price: 20, qty: 2}
] =}
{= invoice_price: 0 =}
{= tax: 20 =}
[$products] {= invoice_price: (# {
Invoice price: {#invoice_price:2.#}
Tax: {#tax:2.#}
{= invoice_price: (# {
Total price: {#invoice_price:2.#}
Invoice price: 90.00
Tax: 20.00
Total price: 110.00
Fixed bugs
Add new functionality: capsules!, with the symbol of Div logo!.... of course!
Now you can create capsules inside the insole to reduce the code and to facilitate
the work with objects and arrangements. A capsule consists on a block that fulfills
the following syntax:
[[variable
... In this section you can use the properties of variable if it is
an object or their keys if it is an array ...
variable]]
For example:
[[product
Name: {
product]]
Enjoy!
Add new feature for iterations functionality: now you can specify a STEP for iteration.
Variant 1:
[:from,to,var,step:]
Variant 2:
[:from,to,step:]
Template:
[:1,10,2:] {$value} [/]
Output:
1 3 5 7 9
[:1,10,i,2:] {$i} [/]
Output:
1 3 5 7 9
[:10,1,i,2:] {$i} [/]
10 8 6 4 2
Another way to define the iteration var with high priority. Now the follow templates are similars:
Template 1:
[:1,10,x:] .... [/]
Template 2:
[:1,10:] x => .... [/]
The follow example shows the priority of this new way:
Template:
[:1,10,x:] y => {
Output:
1 {
Added aggregate functions for the lists: sum, avg, min, max, and the default count function
Now the designer can calculate another statistics from lists, for example:
index.php
index.tpl
Minimum price: {
Average of prices: {
Count of products with price: {
Minimum value: {
Average of values: {
Added a new constant constant DIV_CLASS_NAME for define the name of de superclass of div.
Now the programmer can change the name of the div class to avoid possible
collisions the class's names of his application.
Added a new functionality: default replacements by variable.
Now the programmer and the designer can define the default replacements for values
by variable. For example:
Set the default replacement in PHP:
true)); ?>Or set the default replacement in the template:
...
{@["kept", true, "YES"]@}
{@["kept", false, "NO"]@}
...
Enable two new properties for PHP developers: $src and $packages.
See the follow example:
If you want that the names of the files have a prefix, specify it in constant
PACKAGES or in the property $__packages of a class that extends the div. See
the following examples:
Example 1
Example 2
Add new constant DIV_DEFAULT_TPL_FILE_EXT for define a template file extension.
You can define this constant BEFORE include the div.php script. The default value
for this constant is the string "tpl". For example:
Add new constant DIV_DEFAULT_DATA_FILE_EXT for define a data file extension.
You can define this constant BEFORE include the div.php script. The default value
for this constant is the string "json". For example:
Implement the show() method.
show(); ?>If you don't pass the value of $src for the div class constructor, then
Div assumes that $src is the name of the class :)
Enable the div extends for OOP in the programmer side. The name of the properties
should not begin with __ (double underscore). See the follow example:
Page.tpl
Added a new variable for the cycles: $_order, that is $_index + 1.
The index begins with 0. The order bigins with 1. This is util when you
need build a ordered list without
For example:
The ordered list:
[$list]
{% reused %}
[/$list]
The reused template reused.tpl:
?
On the other hand if you use the following template for reuse.tpl,
the first order number will be hidden and the template is more complicated:
?
Added new variable's modifiers: html and br
{html:variable} convert all applicable chracters to HTML entities (see the
documentation of htmlentities() PHP function)
{br:variable} convert all \n to
Fixed bugs of recursivity and recovered the high priority of variables into the cycles.
Release the 2.0 Version
Fix some grave bugs of iterations functionality and other improvements.
Added a new functionalitites:
{= clients: [
{
name: 'John',
products: [{name: 'Banana', price: 1.2},{name: 'Potato', price: 1.3}]
}
]
=}
[$clients] client =>
[$products]
{
[/$products]
[/$clients]
Custom item variable for iterations: you now can specify the iteration variable. For example:
[:1,100,i:]
The current value is {$i}
[/]
Nested iterations. The following example...
[:1,10,i:]
[:1,10,j:]
{
[/]
[/]
...is similar to:
"; ?>New variable for iterations and lists's cycle
$_list, that it contains the list's name.
For example:
[$products]
{
Div associates a name to each iteration that you define. With this new functionality
you can know the name of the iteration inside the cycle of the iteration.
Also, if you use the recursion, you can work now with the name of the list thanks to
this new variable that doesn't collapse with a variable inside the cycle.
For example:
{= list: "products",
products: [
count: 3,
list: ["Banana", "Potato" , "Rice"]
]
=}
[{$list}]
{
{
[$list] <--{ and this list is a list into the parent cycle }-->
{
[/{$list}]
$_item, that it contains the list's item
For example:
{= products: [
{
name: "Banana",
price: 1.2
},
{
name: "Potato",
price: 1.3
}
] =}
[$products]
{
$_key, that it contains the item's key
For example:
[$products]
[$_item]
{
[/$_item]
[/$products]
Release the 1.9 version
Recovering a lost functionality. In version 1.5 to make the algorithms more efficient
we made a mistake and break functionality of the clean the orphan parts. Now in version 1.8
is working again just as quickly.
Fix some grave bugs.
Added new funtionalities:
If a var contain an object, {$var} will be repleace with the count of properties
Sub matches: now you can write (
substr($var, 0, 20);
With this new functionality you can chop a text in half thank
to the formulas, for example:
{
You can also make use of the variable's modifiers:
{^text: 1}
Release the 1.8 version.
Note: The new added features made a little slower the engine. We are working
in the improvement of the algorithms.
// ignoring the "name" variable
echo new div("index.tpl", array("name" => "Salvi", "age" => 25), array("name"));
The algorithm was improved. Div is faster now.
Fixed bugs.
A new variable's modifier was added to encode URL. For example:
{&variable}
Release the 1.5 version
Fixed bugs of blocks of conditions
Add new feature named ITERATIONS.
Example:
[:1,5:] {$value} [/]
Output:
1 2 3 4 5
Release the 1.4 version
Fixing some several issues of conditional parts!
Release the 1.1 version